package com.huitu.whht.base.core.api.wr.mp;

import com.huitu.api.rest.AbstractApiResource;
import com.huitu.commons.PageUtils;
import com.huitu.whht.api.core.common.response.ApiResultBuilder;
import com.huitu.whht.api.core.common.annotations.SzyCoreApiResource;
import com.huitu.whht.api.core.common.annotations.SzyCoreApiService;
import com.huitu.whht.api.core.common.response.StatusRespBuilder;
import com.huitu.whht.api.core.common.util.LocalDateTimeUtil;
import java.time.LocalDateTime;
import com.huitu.whht.base.core.api.wr.mp.entities.WrMpHourwR;
import com.huitu.whht.base.core.api.wr.mp.entities.WrMpHourwRKey;
import com.huitu.whht.base.core.api.wr.mp.entities.WrMpHourwRQo;
import com.huitu.whht.base.core.api.wr.mp.service.IWrMpHourwRService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
 * 说明: 取用水小时水量表API,表名称: WR_MP_HOURW_R <br/>
 * 日期: 2019-04-15
 * @author LiuCW
 */
@Component
@SzyCoreApiResource
@Path("wr/mp/hourw/r")
public class WrMpHourwRResource extends AbstractApiResource {

    private static final Logger LOGGER = LoggerFactory.getLogger(WrMpHourwRResource.class);

    private static final String UUID = "0118bfeb-4475-4f66-8b2c-2398a68bd35b";

    @Override
    public String getUUID() {
        return UUID;
    }

    @Autowired
    @SzyCoreApiService
    IWrMpHourwRService wrMpHourwRService;

    /**
     * @api {get} wr/mp/hourw/r/{mpCd:\\w{13}}/{dt} [R][G]根据主键查询
     * @apiDescription [G]根据主键查询WR_MP_HOURW_R(取用水小时水量表)数据
     * @apiName (generate)select by primary key
     * @apiGroup WR_MP_HOURW_R-取用水小时水量表
     * @apiVersion 1.0.0
     * @apiSampleRequest wr/mp/hourw/r/4209020004001/2016-07-13 13:00:00
     * @apiParam   {String}         mpCd               【必须】监测点代码
     * @apiParam   {Date}           dt                 【必须】日期
     * @apiSuccess {String}         mpCd               监测点代码
     * @apiSuccess {Date}           dt                 日期(时间格式 <font color='red'>yyyy-MM-dd HH:mm:ss</font>)
     * @apiSuccess {Double}         hourW              小时水量
     * @apiSuccess {String}         speRegData         特殊区域
     * @apiSuccess {Date}           ts                 时间戳(时间格式 <font color='red'>yyyy-MM-dd HH:mm:ss</font>)
     * @apiSuccessExample 请求成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "mpCd": "4209020004001",
     * "dt": "2016-07-13 13:00:00.0",
     * "hourW": 118,
     * "speRegData": "0",
     * "ts": "2016-07-13 14:48:19.0"
     *  }
     * }
     * @apiUse exceptions
     */
    @GET
    @Path("{mpCd:\\w{13}}/{dt}")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response selectByPrimaryKey(@PathParam("mpCd") String mpCd,@PathParam("dt") String dt) {
        WrMpHourwRKey pk = new WrMpHourwRKey();
        pk.setMpCd(mpCd);
        LocalDateTime.parse(dt,LocalDateTimeUtil.DATE_TIME_FORMATTER_YMD_HMS);
        LOGGER.info("根据主键查询 取用水小时水量表,参数 pk:{}", pk);
        return Response.ok(ApiResultBuilder.create(this, wrMpHourwRService.selectByPrimaryKey(pk))).build();
    }

    /**
     * @api {post} wr/mp/hourw/r/list [R][G]根据条件查询
     * @apiDescription [G]根据条件查询WR_MP_HOURW_R(取用水小时水量表)数据
     * @apiName (generate)select by filter
     * @apiGroup WR_MP_HOURW_R-取用水小时水量表
     * @apiVersion 1.0.0
     * @apiSampleRequest wr/mp/hourw/r/list
     * @apiParam   {List(String)}   mpCdList           (数组)监测点代码
     * @apiParam   {String}         mpCd               监测点代码
     * @apiParam   {Date}           dtBgTm             (开始时间)日期
     * @apiParam   {Date}           dtEdTm             (结束时间)日期
     * @apiParam   {Double}         hourWMin           (最小)小时水量
     * @apiParam   {Double}         hourWMax           (最大)小时水量
     * @apiParam   {List(String)}   speRegDataList     (数组)特殊区域
     * @apiParam   {Date}           tsBgTm             (开始时间)时间戳
     * @apiParam   {Date}           tsEdTm             (结束时间)时间戳
     * @apiSuccess {String}         mpCd               监测点代码
     * @apiSuccess {Date}           dt                 日期
     * @apiSuccess {Double}         hourW              小时水量
     * @apiSuccess {String}         speRegData         特殊区域
     * @apiSuccess {Date}           ts                 时间戳
     * @apiSuccessExample 请求成功:
     * HTTP/1.1 200 OK
     * {
     * "result": [{
     * "mpCd": "4209020004001",
     * "dt": "2016-07-13 13:00:00.0",
     * "hourW": 118,
     * "speRegData": "0",
     * "ts": "2016-07-13 14:48:19.0"
     *  }]
     * }
     *
     * @apiSuccessExample 分页请求:
     * request header: Rang={max=50;size=50;field=TS DESC}
     * HTTP/1.1 200 OK
     * {
     * "result": [{
     * "mpCd": "4209020004001",
     * "dt": "2016-07-13 13:00:00.0",
     * "hourW": 118,
     * "speRegData": "0",
     * "ts": "2016-07-13 14:48:19.0"
     *  }],
     * "paging": {
     * "count": 3,
     * "total": 120,
     * "finale": false,
     * "index": 1
     * }
     * }
     * @apiUse header_rang
     * @apiUse exceptions
     */
    @POST
    @Path("list")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response selectList(WrMpHourwRQo filter) {
        PageUtils.startPageFromRang();
        LOGGER.info("根据条件查询 取用水小时水量表,参数 WrMpHourwRQo:{}", filter);
        return Response.ok(ApiResultBuilder.create(this, wrMpHourwRService.selectList(filter))).build();
    }

    /**
     * @api {put} wr/mp/hourw/r [C][G]新增数据
     * @apiPrivate
     * @apiDescription [G]新增WR_MP_HOURW_R(取用水小时水量表)数据
     * @apiName (generate)add data
     * @apiGroup WR_MP_HOURW_R-取用水小时水量表
     * @apiVersion 1.0.0
     * @apiParam   {String}         mpCd               【必须】监测点代码
     * @apiParam   {Date}           dt                 【必须】日期(时间格式 <font color='red'>yyyy-MM-dd HH:mm:ss</font>)
     * @apiParam   {Double}         hourW              小时水量
     * @apiParam   {String}         speRegData         特殊区域
     * @apiParam   {Date}           ts                 时间戳(时间格式 <font color='red'>yyyy-MM-dd HH:mm:ss</font>)
     * @apiSuccess {Integer}        status             1:新增成功;0:新增失败.
     * @apiSuccess {String}         message            成功/失败消息内容
     * @apiSuccess {Object}         data               额外返回的数据,通常包含新增数据的主键值
     * @apiSampleRequest wr/mp/hourw/r
     * @apiSuccessExample 新增成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":{
     *   "mpCd": "4209020004001",
     *   "dt": "2016-07-13 13:00:00.0"
     *      }
     *   }
     * }
     @apiSuccessExample 新增失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":{
     *   "mpCd": "4209020004001",
     *   "dt": "2016-07-13 13:00:00.0"
     *      }
     *   }
     * }
     * @apiParamExample {json} 请求示例:
     * {
     * "mpCd": "4209020004001",
     * "dt": "2016-07-13 13:00:00.0",
     * "hourW": 118,
     * "speRegData": "0",
     * "ts": "2016-07-13 14:48:19.0"
     * }
     * @apiUse exceptions
     */
    @PUT
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response insert(WrMpHourwR record) {
        LOGGER.info("新增 取用水小时水量表,参数 WrMpHourwR:{}", record);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.insert(wrMpHourwRService.insertSelective(record),record))).build();
    }

    /**
     * @api {post} wr/mp/hourw/r/insertBatch [C][G]批量新增数据
     * @apiPrivate
     * @apiDescription [G]批量新增WR_MP_HOURW_R(取用水小时水量表)数据
     * @apiName (generate)addBatch data
     * @apiGroup WR_MP_HOURW_R-取用水小时水量表
     * @apiVersion 1.0.0
     * @apiParam   {String}         mpCd               【必须】监测点代码
     * @apiParam   {Date}           dt                 【必须】日期(时间格式 <font color='red'>yyyy-MM-dd HH:mm:ss</font>)
     * @apiParam   {Double}         hourW              小时水量
     * @apiParam   {String}         speRegData         特殊区域
     * @apiParam   {Date}           ts                 时间戳(时间格式 <font color='red'>yyyy-MM-dd HH:mm:ss</font>)
     * @apiSuccess {Integer}        status             1:新增成功;0:新增失败.
     * @apiSuccess {String}         message            成功/失败消息内容
     * @apiSuccess {Object}         data               额外返回的数据,通常包含新增数据的主键值
     * @apiSampleRequest wr/mp/hourw/r/insertBatch
     * @apiSuccessExample 新增成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":{
     *   "mpCd": "4209020004001",
     *   "dt": "2016-07-13 13:00:00.0"
     *      }
     *   }
     * }
     @apiSuccessExample 新增失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":{
     *   "mpCd": "4209020004001",
     *   "dt": "2016-07-13 13:00:00.0"
     *      }
     *   }
     * }
     * @apiParamExample {json} 请求示例:
     * [{
     * "mpCd": "4209020004001",
     * "dt": "2016-07-13 13:00:00.0",
     * "hourW": 118,
     * "speRegData": "0",
     * "ts": "2016-07-13 14:48:19.0"
     * }]
     * @apiUse exceptions
     */
    @POST
    @Path("insertBatch")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response insertBatch(List<WrMpHourwR> recordList) {
        LOGGER.info("批量新增 取用水小时水量表,参数 WrMpHourwR:[]", recordList);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.insert(wrMpHourwRService.insertBatch(recordList),recordList))).build();
    }

    /**
     * @api {put} wr/mp/hourw/r/{mpCd:\\w{13}}/{dt}/update [U][G]根据主键修改
     * @apiPrivate
     * @apiDescription [G]根据主键修改WR_MP_HOURW_R(取用水小时水量表)数据
     * @apiName (generate)update data
     * @apiGroup WR_MP_HOURW_R-取用水小时水量表
     * @apiVersion 1.0.0
     * @apiParam   {String}         mpCd               【必须】监测点代码
     * @apiParam   {Date}           dt                 【必须】日期
     * @apiParam   {Double}         hourW              小时水量
     * @apiParam   {String}         speRegData         特殊区域
     * @apiParam   {Date}           ts                 【必须】时间戳
     * @apiSuccess {Integer}        status             1:修改成功;0:要修改的数据不存在(可能已被删除)
     * @apiSuccess {String}         message            成功/失败消息内容
     * @apiSuccess {Object}         data               额外返回的数据
     * @apiSampleRequest wr/mp/hourw/r/4209020004001/2016-07-13 13:00:00/update
     * @apiSuccessExample 修改成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":null
     *   }
     * }
     * @apiSuccessExample 修改失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":null
     *   }
     * }
     * @apiParamExample {json} 请求示例:
     * {
     * "mpCd": "4209020004001",
     * "dt": "2016-07-13 13:00:00.0",
     * "hourW": 118,
     * "speRegData": "0",
     * "ts": "2016-07-13 14:48:19.0"
     * }
     * @apiUse exceptions
     */
    @PUT
    @Path("{mpCd:\\w{13}}/{dt}/update")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response update(@PathParam("mpCd") String mpCd,@PathParam("dt") String dt, WrMpHourwR record) {
        record.setMpCd(mpCd);
        LocalDateTime.parse(dt,LocalDateTimeUtil.DATE_TIME_FORMATTER_YMD_HMS);
        LOGGER.info("根据主键修改 取用水小时水量表,参数 WrMpHourwR:{}", record);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.update(wrMpHourwRService.updateByPrimaryKey(record)))).build();
    }

    /**
     * @api {put} wr/mp/hourw/r/{mpCd:\\w{13}}/{dt}/update-selective [U][G]根据主键修改(只修改非null字段)
     * @apiPrivate
     * @apiDescription [G]根据主键修改WR_MP_HOURW_R(取用水小时水量表)数据,只修改非null字段
     * @apiName (generate)update selected data
     * @apiGroup WR_MP_HOURW_R-取用水小时水量表
     * @apiVersion 1.0.0
     * @apiParam   {String}         mpCd               监测点代码
     * @apiParam   {Date}           dt                 日期
     * @apiParam   {Double}         hourW              小时水量
     * @apiParam   {String}         speRegData         特殊区域
     * @apiParam   {Date}           ts                 时间戳
     * @apiSuccess {Integer}        status             1:修改成功;0:要修改的数据不存在(可能已被删除)
     * @apiSuccess {String}         message            成功/失败消息内容
     * @apiSuccess {Object}         data               额外返回的数据
     * @apiSampleRequest wr/mp/hourw/r/4209020004001/2016-07-13 13:00:00/update-selective
     * * @apiSuccessExample 修改成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":null
     *   }
     * }
     * @apiSuccessExample 修改失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":null
     *   }
     * }
     * @apiParamExample {json} 请求示例:
     * {
     * "mpCd": "4209020004001",
     * "dt": "2016-07-13 13:00:00.0",
     * "hourW": 118,
     * "speRegData": "0",
     * "ts": "2016-07-13 14:48:19.0"
     * }
     * @apiUse exceptions
     */
    @PUT
    @Path("{mpCd:\\w{13}}/{dt}/update-selective")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response updateSelective(@PathParam("mpCd") String mpCd,@PathParam("dt") String dt, WrMpHourwR record) {
        record.setMpCd(mpCd);
        LocalDateTime.parse(dt,LocalDateTimeUtil.DATE_TIME_FORMATTER_YMD_HMS);
        LOGGER.info("根据主键修改(只修改非null字段) 取用水小时水量表,参数 WrMpHourwR:{}", record);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.update(wrMpHourwRService.updateByPrimaryKeySelective(record)))).build();
    }

    /**
     * @api {post} wr/mp/hourw/r/updateBatch [U][G]根据主键批量修改(只修改非null字段)
     * @apiPrivate
     * @apiDescription [G]根据批量主键修改WR_MP_HOURW_R(取用水小时水量表)数据,只修改非null字段
     * @apiName (generate)updateBatch selected data
     * @apiGroup WR_MP_HOURW_R-取用水小时水量表
     * @apiVersion 1.0.0
     * @apiParam   {String}         mpCd               监测点代码
     * @apiParam   {Date}           dt                 日期
     * @apiParam   {Double}         hourW              小时水量
     * @apiParam   {String}         speRegData         特殊区域
     * @apiParam   {Date}           ts                 时间戳
     * @apiSuccess {Integer}        status             1:修改成功;0:要修改的数据不存在(可能已被删除)
     * @apiSuccess {String}         message            成功/失败消息内容
     * @apiSuccess {Object}         data               额外返回的数据
     * @apiSampleRequest  wr/mp/hourw/r/updateBatch
     * * @apiSuccessExample 修改成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":null
     *   }
     * }
     * @apiSuccessExample 修改失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":null
     *   }
     * }
     * @apiParamExample {json} 请求示例:
     * [{
     * "mpCd": "4209020004001",
     * "dt": "2016-07-13 13:00:00.0",
     * "hourW": 118,
     * "speRegData": "0",
     * "ts": "2016-07-13 14:48:19.0"
     * }]
     * @apiUse exceptions
     */
    @POST
    @Path("updateBatch")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response updateBatch(List<WrMpHourwR> record) {
        LOGGER.info("根据主键批量修改(只修改非null字段) 取用水小时水量表,参数 WrMpHourwR:{}", record);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.update(wrMpHourwRService.updateBatch(record)))).build();
    }

    /**
     * @api {delete} wr/mp/hourw/r/{mpCd:\\w{13}}/{dt} [D][G]根据主键删除
     * @apiPrivate
     * @apiDescription [G]根据主键删除WR_MP_HOURW_R(取用水小时水量表)数据
     * @apiName (generate)delete by primary key
     * @apiGroup WR_MP_HOURW_R-取用水小时水量表
     * @apiVersion 1.0.0
     * @apiSampleRequest wr/mp/hourw/r/4209020004001/2016-07-13 13:00:00
     * @apiParam   {String}         mpCd               【必须】监测点代码
     * @apiParam   {Date}           dt                 【必须】日期
     * @apiSuccess {Integer}        status             1:删除成功;0:要删除的数据不存在(可能已被删除).
     * @apiSuccess {String}         message            成功/失败消息内容
     * @apiSuccess {Object}         data               额外返回的数据
     * @apiSuccessExample 删除成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":null
     *   }
     * }
     * @apiSuccessExample 删除失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":null
     *   }
     * }
     * @apiUse exceptions
     */
    @DELETE
    @Path("{mpCd:\\w{13}}/{dt}")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response delete(@PathParam("mpCd") String mpCd,@PathParam("dt") String dt) {
         WrMpHourwRKey pk = new WrMpHourwRKey();
        pk.setMpCd(mpCd);
        LocalDateTime.parse(dt,LocalDateTimeUtil.DATE_TIME_FORMATTER_YMD_HMS);
        LOGGER.info("根据主键删除 取用水小时水量表,参数 pk:{}", pk);
        Integer rows = wrMpHourwRService.deleteByPrimaryKey(pk);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.delete(rows))).build();
    }

    /**
     * @api {delete} wr/mp/hourw/r/by-filter [D][G]根据条件删除
     * @apiPrivate
     * @apiDescription [G]根据条件删除WR_MP_HOURW_R(取用水小时水量表)数据
     * @apiName (generate)delete by filter
     * @apiGroup WR_MP_HOURW_R-取用水小时水量表
     * @apiVersion 1.0.0
     * @apiSampleRequest wr/mp/hourw/r/by-filter
     * @apiParam   {List(String)}   mpCdList           (数组)监测点代码
     * @apiParam   {String}         mpCd               监测点代码
     * @apiParam   {Date}           dtBgTm             (开始时间)日期
     * @apiParam   {Date}           dtEdTm             (结束时间)日期
     * @apiParam   {Double}         hourWMin           (最小)小时水量
     * @apiParam   {Double}         hourWMax           (最大)小时水量
     * @apiParam   {List(String)}   speRegDataList     (数组)特殊区域
     * @apiParam   {Date}           tsBgTm             (开始时间)时间戳
     * @apiParam   {Date}           tsEdTm             (结束时间)时间戳
     * @apiSuccess {Integer}        status             通常1或者>1:删除成功;0:没有符合条件的数据.
     * @apiSuccess {String}         message            成功/失败消息内容
     * @apiSuccess {Object}         data               额外返回的数据
     * @apiSuccessExample 删除成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":null
     *   }
     * }
     * @apiSuccessExample 删除失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":null
     *   }
     * }
     * @apiUse exceptions
     */
    @DELETE
    @Path("by-filter")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response deleteByFilter(WrMpHourwRQo filter) {
        LOGGER.info("根据条件删除 取用水小时水量表,参数 WrMpHourwRQo:{}", filter);
        Integer rows = wrMpHourwRService.deleteByFilter(filter);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.delete(rows))).build();
    }
}
